#include "PoolFactory.hpp"
#include <gflags/gflags.h>
#include "Result.hpp"
// mysql信息
DEFINE_string(mysql_host, "127.0.0.1", "这是Mysql服务器地址");
DEFINE_int32(mysql_port, 3306, "这是Mysql服务器端口");
DEFINE_string(mysql_db, "TestDb", "数据库默认库名称");
DEFINE_string(mysql_user, "conn", "这是Mysql用户名");
DEFINE_string(mysql_pwd, "123456", "这是Mysql密码");
DEFINE_string(mysql_cset, "utf8", "这是Mysql客户端字符集");
DEFINE_int32(mysql_max_pool, 3, "这是Mysql连接池最大连接数量");
int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    auto pool = MySQLPoolFactory::create(1, FLAGS_mysql_host, FLAGS_mysql_port, FLAGS_mysql_user,
                                         FLAGS_mysql_pwd, FLAGS_mysql_db);
    for (int i = 0; i < 10; ++i)
    {
        auto conn = pool->GetAliveConn();
        auto res = conn->query("select* from person");
        Result r(res);
        auto json_res = r.result();
        int n = json_res.size();
        std::cout<<"表中数据量: "<<n<<std::endl;
        for(const auto& data : json_res)
        {
            std::cout<<data["id"].asString()<<std::endl;
            std::cout<<data["name"].asString()<<std::endl;
            std::cout<<data["age"].asString()<<std::endl;
        }
    }
    return 0;
}